<template>
  <div class="orderstatus-container">
    <div class="order-status">
      <h2>订单号: {{ orderNumber }}</h2>
      <h3>待收货</h3>
      <button class="confirm-receipt" @click="confirmReceipt">确认收货</button>
      <div class="timeline">
        <div class="timeline-item">提交订单 <span>{{ submittedDate }}</span></div>
        <div class="timeline-item">支付订单 <span>{{ paidDate }}</span></div>
        <div class="timeline-item">卖家发货 <span>{{ shippedDate }}</span></div>
        <div class="timeline-item">完成 <span>(买家确认收货)</span></div>
      </div>
    </div>
</div>
</template>

<script>
import { mapState } from 'vuex';

export default {
  computed: {
    // 从 Vuex 中获取 id
    orderId() {
      return this.$route.params.orderindex;
      // return this.$store.state.messages[0].orderId; // 假设消息列表中第一个订单的 ID
    }
  },
  data() {
    return {
      // 其他静态订单数据
      orderId: this.$route.params.orderindex,
      orderNumber: '241210215113444',
      submittedDate: '2024-12-10 21:51:13',
      paidDate: '2024-12-10 21:51:48',
      shippedDate: '2024-12-11 23:41:13',
      isReceived: false,
    };
  },
  methods: {
    confirmReceipt() {
      // 通过 Vuex 删除消息，使用动态获取的 orderId
      this.$store.dispatch('deleteMessage', this.orderId);  // 使用 Vuex 中的 orderId 删除消息
      // console.log(this.orderId);

      // 跳转回消息页面
      // this.$router.push({ name: 'SystemMessage' });
      // 跳转到成功页面
      this.$router.push({ name: 'OK' });
    }
  }
};
</script>

<style scoped>
.orderstatus-container {
  max-width: 400px;
  margin: 28vh auto;
  padding: 20px;
  background-color: #fff;
  border-radius: 5px;
}

.order-status {
  width: 400px;
  margin: 0 auto;
  padding: 20px;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  background-color: #f9f9f9;
}

.confirm-receipt {
  display: block;
  width: 100px;
  padding: 10px;
  margin: 20px auto;
  background-color: #4CAF50;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.confirm-receipt:hover {
  background-color: #45a049;
}

.timeline {
  margin-top: 20px;
}

.timeline-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;  /* 增加上下内边距 */
  border-bottom: 1px solid #e0e0e0;
  font-size: 14px;
  min-height: 40px; /* 确保每一项都有一个最小高度 */
}

.timeline-item:last-child {
  border-bottom: none;
}

.timeline-item span {
  flex: 1;  /* 确保每个时间信息都占据剩余空间 */
  text-align: right;  /* 时间内容右对齐 */
  font-weight: bold;
}


</style>
